import os

from flask import Flask, Blueprint

from plugins.dev.views import init_bp

dir_path = os.path.dirname(os.path.realpath(__file__)).replace("\\", "/")
plugin_path = dir_path[dir_path.rfind("/")+1:]

dev_bp = Blueprint("dev", __name__, url_prefix="/dev", template_folder='templates',
               static_folder='static')

def event_init(app: Flask):
    init_bp(dev_bp)
    app.register_blueprint(dev_bp)

def event_enable(app: Flask):
    pass

def event_disable(app: Flask):
    pass

def event_install(app: Flask):
    if os.path.exists(dir_path + "/requirements.txt"):
        app.logger.info("正在安装依赖... for plugin " + plugin_path)
        os.system("pip install -r " + dir_path + "/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple")

def event_remove(app: Flask):
    pass
